VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDanhMucMonHoc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private m_sMaMH As String
Private m_sMaNganh As String
Private m_sTenMH As String
Private m_iSoHT As Integer
Private m_iHocKy As Integer

Public Property Get mamh() As String
    mamh = m_sMaMH
End Property

Public Property Let mamh(ByVal sMaMH As String)
    m_sMaMH = sMaMH
End Property

Public Property Get manganh() As String
    manganh = m_sMaNganh
End Property

Public Property Let manganh(ByVal sMaNganh As String)
    m_sMaNganh = sMaNganh
End Property

Public Property Get TenMH() As String
    TenMH = m_sTenMH
End Property

Public Property Let TenMH(ByVal sTenMH As String)
    m_sTenMH = sTenMH
End Property

Public Property Get soht() As Integer
    soht = m_iSoHT
End Property

Public Property Let soht(ByVal iSoHT As Integer)
    m_iSoHT = iSoHT
End Property

Public Property Get hocky() As Integer
    hocky = m_iHocKy
End Property

Public Property Let hocky(ByVal iHocKy As Integer)
    m_iHocKy = iHocKy
End Property

Public Function TimKiem(ByVal mamh As String, ByVal TenMH As String, ByVal manganh As String, ByVal soht As String, ByVal hocky As String) As ADODB.Recordset
    Dim sql As String
    
   On Error GoTo TimKiem_Error

    sql = "SELECT mh.*, TenNganh FROM DanhMucMonHoc mh, Nganh ng " & _
            "WHERE MaMH = " & IIf(mamh <> "", "'" & mamh & "'", "MaMH") & " AND " & _
                  "TenMH = " & IIf(TenMH <> "", "'" & TenMH & "'", "TenMH") & " AND " & _
                  "mh.MaNganh = " & IIf(manganh <> "", "'" & manganh & "'", "mh.MaNganh") & " AND " & _
                  "SoHT = " & IIf(soht <> "", "'" & soht & "'", "SoHT") & " AND " & _
                  "HocKy = " & IIf(hocky <> "", "'" & hocky & "'", "HocKy") & " AND " & _
                  "mh.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set TimKiem = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
TimKiem_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure TimKiem of Class Module clsDanhMucMonHoc"
End Function

Public Function ThongKe(ByVal manganh As String, ByVal soht As String, ByVal hocky As String) As ADODB.Recordset
    Dim sql As String
   On Error GoTo ThongKe_Error

    sql = "SELECT mh.*, TenNganh FROM DanhMucMonHoc mh, Nganh ng " & _
            "WHERE mh.MaNganh = " & IIf(manganh <> "", "'" & manganh & "'", "mh.MaNganh") & " AND " & _
                  "SoHT = " & IIf(soht <> "", "'" & soht & "'", "SoHT") & " AND " & _
                  "HocKy = " & IIf(hocky <> "", "'" & hocky & "'", "HocKy") & " AND " & _
                  "mh.MaNganh = ng.MaNganh"
    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set ThongKe = g_ObjADOConn.Execute(sql)

   On Error GoTo 0
   Exit Function
ThongKe_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ThongKe of Class Module clsDanhMucMonHoc"
End Function
'---------------------------------------------------------------------------------------
' Procedure : SelectAll
' Date      : 27/10/2011
' Purpose   : Load danh sach tat ca record cua table co trong file du lieu
'---------------------------------------------------------------------------------------
Public Function SelectAll() As ADODB.Recordset
   On Error GoTo SelectAll_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectAll = g_ObjADOConn.Execute("SELECT mh.*, TenNganh FROM DanhMucMonHoc mh, Nganh ng WHERE mh.MaNganh = ng.MaNganh")

   On Error GoTo 0
   Exit Function
SelectAll_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectAll of Class Module clsDanhMucMonHoc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : SelectByID
' Date      : 27/10/2011
' Purpose   : Lay record cua table ung voi ma DanhMucMonHoc truyen vao
'---------------------------------------------------------------------------------------
Public Function SelectByID(ByVal ID As String) As ADODB.Recordset
   On Error GoTo SelectByID_Error

    Call OpenConnection
    ' Create a Recordset by executing an SQL statement.
    Set SelectByID = g_ObjADOConn.Execute("SELECT mh.*, TenNganh FROM DanhMucMonHoc mh, Nganh ng WHERE mh.MaNganh = ng.MaNganh AND MaMH = '" & ID & "'")

   On Error GoTo 0
   Exit Function
SelectByID_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectByID of Class Module clsDanhMucMonHoc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Insert
' Date      : 27/10/2011
' Purpose   : Them 1 record moi vao table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Insert(ByVal ObjDanhMucMonHoc As clsDanhMucMonHoc) As Boolean
    
   On Error GoTo Insert_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("INSERT INTO DanhMucMonHoc(MaMH, MaNganh, TenMH, SoHT, HocKy) " & _
                          "VALUES('" & ObjDanhMucMonHoc.mamh & "', '" & ObjDanhMucMonHoc.manganh & "', '" & ObjDanhMucMonHoc.TenMH & "', '" & ObjDanhMucMonHoc.soht & "', '" & ObjDanhMucMonHoc.hocky & "')")
    Call CloseConnection
    Insert = True
    
   On Error GoTo 0
   Exit Function
Insert_Error:
    Insert = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Insert of Class Module clsDanhMucMonHoc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Delete
' Date      : 27/10/2011
' Purpose   : Xoa 1 record cua table trong file du lieu
'---------------------------------------------------------------------------------------
Public Function Delete(ByVal ID As String) As Boolean
   On Error GoTo Delete_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("DELETE FROM DanhMucMonHoc WHERE MaMH='" & ID & "'")
    Call CloseConnection
    Delete = True
    
   On Error GoTo 0
   Exit Function
Delete_Error:
    Delete = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Delete of Class Module clsDanhMucMonHoc"
End Function

'---------------------------------------------------------------------------------------
' Procedure : Update
' Date      : 27/10/2011
' Purpose   : Update record cua table dua tren ID truyen vao
'---------------------------------------------------------------------------------------
Public Function Update(ByVal ObjDanhMucMonHoc As clsDanhMucMonHoc) As Boolean
   On Error GoTo Update_Error

    Call OpenConnection
    g_ObjADOConn.Execute ("UPDATE DanhMucMonHoc " & _
                          "SET TenMH = '" & ObjDanhMucMonHoc.TenMH & "', " & _
                              "SoHT = '" & ObjDanhMucMonHoc.soht & "', " & _
                              "HocKy = '" & ObjDanhMucMonHoc.hocky & "' " & _
                          "WHERE MaMH = '" & ObjDanhMucMonHoc.mamh & "'")
    Call CloseConnection
    Update = True

   On Error GoTo 0
   Exit Function
Update_Error:
    Update = False
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Update of Class Module clsDanhMucMonHoc"
End Function

